package com.gran.mydemo.examples;

import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
/*import android.content.pm.IPackageInstallObserver;
import android.content.pm.IPackageDeleteObserver;*/
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;



public class InstallAndRemoveApk extends Activity {
	 /*  *//** Called when the activity is first created. *//*
	 private String APK_NAME = "QQHD-mini.apk";
	    private Button install = null;
	 private Button uninstall = null;
	    private final int INSTALL_COMPLETE = 1;
	 private final int UNINSTALL_COMPLETE = 2;
	    final static int SUCCEEDED = 1;
	    final static int FAILED = 0;
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.install_uninstall);
	        install = (Button) findViewById(R.id.install);
	  uninstall = (Button) findViewById(R.id.uninstall);
	  uninstall.setOnClickListener(listener1);
	        install.setOnClickListener(listener2);
	}
	    private OnClickListener listener2=new  OnClickListener(){
	        public void onClick(View v) {
	            String fileName = Environment.getExternalStorageDirectory() +  "/" + APK_NAME; 
	            Uri uri = Uri.fromFile(new File(fileName));

	            int installFlags = 0;
	            PackageManager pm = getPackageManager();
	            try {
	                PackageInfo pi = pm.getPackageInfo("com.tencent.minihd.qq", 
	                        PackageManager.GET_UNINSTALLED_PACKAGES);
	                if(pi != null) {
	                    installFlags |= PackageManager.INSTALL_REPLACE_EXISTING;
	                }
	            } catch (NameNotFoundException e) {}
	            
	            PackageInstallObserver observer = new PackageInstallObserver();
	            pm.installPackage(uri, observer, installFlags, "com.tencent.minihd.qq");
	        }
	    };
	    
	    class PackageInstallObserver extends IPackageInstallObserver.Stub {
	        public void packageInstalled(String packageName, int returnCode) {
	            Message msg = mHandler.obtainMessage(INSTALL_COMPLETE);
	            msg.arg1 = returnCode;
	            mHandler.sendMessage(msg);
	        }
	    };
	    
	    private Handler mHandler = new Handler() {
	        public void handleMessage(Message msg) {
	            switch (msg.what) {
	                case INSTALL_COMPLETE:
	                    int centerTextLabel;
	                    Drawable centerTextDrawable = null;
	                    if(msg.arg1 == SUCCEEDED) {
	                        Toast.makeText(getApplicationContext(), "install apk SUCCEEDED", Toast.LENGTH_SHORT).show();
	                    } else {}
	                    if (centerTextDrawable != null) {}

	                    break;
	    case UNINSTALL_COMPLETE:
	                    int centerTextLabel2;
	                    Drawable centerTextDrawable2 = null;
	                    if(msg.arg1 == SUCCEEDED) {
	                        Toast.makeText(getApplicationContext(), "uninstall apk SUCCEEDED", Toast.LENGTH_SHORT).show();
	                    } else {}
	                    if (centerTextDrawable2 != null) {}

	                    break; 
	                default:
	                    break;
	            }
	        }
	    };
	 
	 private OnClickListener listener1=new  OnClickListener(){
	        public void onClick(View v) {
	            PackageManager pm = getPackageManager();
	            PackageDeleteObserver observer = new PackageDeleteObserver();
	            pm.removePackageFromPreferred(packageName)
	            pm.deletePackage("com.tencent.minihd.qq", observer, 0);
	        }
	    };
	 
	 private class PackageDeleteObserver extends IPackageDeleteObserver.Stub {
	        public void packageDeleted(String packageName, int returnCode) {
	            Message msg = mHandler.obtainMessage(UNINSTALL_COMPLETE);
	            msg.arg1 = returnCode;
	            mHandler.sendMessage(msg);           
	        }    
	    }*/


}
